<?php

include_once("database.php");

class Reservation {
	
	private $sql;

	public function __construct() {
		$this->sql = Database::getInstance();
	}

//---------------------------------------------------------------------------------------------------
	public function addReservation($date, $idAdherent, $idMateriel, $quantite){

		$retour = array();


			if($this->sql->addReservation($date, $idAdherent, $idMateriel, $quantite)) {
				$retour["message"] =  "reservation OK";
			}else {
				$retour["message"] = "reservation pas OK";
			}

			echo json_encode($retour);

	}



//----------------------------------------------------------------------------------------------------

	public function listeMaterielPourAdherent($idAdherent) {

		$retour = array() ;

		if($this->sql->listeMaterielAdherent($idAdherent)) {
			$retour["message"] = " Liste matériel chargé";

		}else {
			$retour["message"] = " Probleme liste materiel";
		}
	}


//----------------------------------------------------------------------------------------------------
	public function deleteReservation($idReservation){

		$retour = array();

		if($this->sql->deleteReservation($idReservation)) {
			$retour["message"] = "Suppression confirmé";

		}else {
			$retour["message"] = "Suppression impossible";
		}

	}

//-------------------------------------------------------------------------------------------------------

	public function updateReservation($date, $idAdherent, $idMateriel, $quantite, $idReservation){  
		$retour = array();

		if($this->sql->updateReservation($date, $idAdherent, $idMateriel, $quantite, $idReservation)){
			$retour["message"] = "Ok";

		}else {
			$retour["message"] = "Echec de l'update ";

		}


	}




//-------------------------------------------------------------------------------------------------------
	public function showReservation($idReservation){

		$retour = array();

		if($this->sql->showReservation($idReservation)){
			return $this->sql->showReservation($idReservation);

		}else{
			$retour["message"] = "reservation non trouver";

			
		}
		echo json_encode($retour);

	}


//---------------------------------------------------------------------------------------------------------
	public function listReservation()	{

			echo json_encode($this->sql->listReservation());
	}

	public function findReservation($idAssociation, $date, $nomAdherent) {
		echo json_encode($this->sql->findReservation($this->sql->getIdAssoc($idAssociation)->numero_association, $date, $nomAdherent));
	}

	public function infoReservation($idReservation) {
		echo json_encode($this->sql->infoReservation($idReservation));
		
	}


}

?>